
import iconOption from './iconOption'
class Marker {
    constructor() { // objEntity
        this.group = {
            newDiscovery: undefined,
            toVerify: undefined,
            calcConfirmed: undefined,
            processed: undefined,
            pseudoChange: undefined,
            panorama: undefined
        }
        // this.markerImgArr = []
    }
    init(map, AMap) { // 实例出不同组
        for (const key in this.group) {
            if (this.group.hasOwnProperty(key)) {
                this.group[key] = new AMap.OverlayGroup()
                map.add(this.group[key])
            }
        }
    }
    groupShow(key) {
        this.group[key].show()
    }
    groupHide(key) {
        this.group[key].hide()
    }
    addOverlay(markArr, fu, AMap) {
        // const markers = []
        markArr.forEach(item => {
            const lnglat = item.position
            const size = iconOption[item.type].size
            const imageSize = iconOption[item.type].imageSize
            const Icon = new AMap.Icon({
                size: new AMap.Size(size, size),
                image: iconOption[item.type].image,
                imageSize: new AMap.Size(imageSize, imageSize)
            })
            const marker = new AMap.Marker({
                position: new AMap.LngLat(lnglat[0], lnglat[1]),
                icon: Icon,
                extData: {
                    id: item.id,
                    type: item.type,
                    class: item.class
                }
            })
            marker.on('click', fu)
            // markers.push(marker)
            this.group[item.type].addOverlay(marker)
        })
    }
    // clusterer(map, AMap) {
    //     var styles = [{
    //         url: 'imgs/1.png',
    //         size: new AMap.Size(32, 32),
    //         offset: new AMap.Pixel(-16, -30)
    //     },
    //     {
    //         url: 'imgs/2.png',
    //         size: new AMap.Size(32, 32),
    //         offset: new AMap.Pixel(-16, -30)
    //     },
    //     {
    //         url: 'imgs/3.png',
    //         size: new AMap.Size(48, 48),
    //         offset: new AMap.Pixel(-24, -45),
    //         textColor: '#CC0066'
    //     }]
    //     // 添加聚合组件
    //     map.plugin(['AMap.MarkerClusterer'], function () {
    //         cluster = new AMap.MarkerClusterer(
    //             map,     // 地图实例
    //             markers,    // 海量点组成的数组
    //             {
    //                 styles: styles
    //             })
    //     })
    // }
    removeOverlay() {

    }
    initOverlayStatus(option) {
        for (const key in option) {
            if (option.hasOwnProperty(key)) {
                if (option[key]) {
                    this.groupShow(key)
                } else {
                    this.groupHide(key)
                }
            }
        }
    }
    getMarker(map, id) {
        const markers = map.getOverlays()
        return markers.find((value, index, arr) => {
            return value.getExtData().id === id
        })
    }
}
const MARKER = new Marker()

export default MARKER